Page({
  data: {
    val: "",
    todoList: []
  },
  onShow() {
    console.log(getCurrentPages())
    this.getList()
  },
  handleSubmit() {
    if(this.data.val) {
      const self = this
      wx.request({
        method: "POST",
        url: "https://api.yizhanketang.cn/api/v1/todos",
        data: {
          content: self.data.val
        },
        success(res) {
          self.getList()
          self.setData({
            val: ""
          })
        }
      })
    } else {
      wx.showToast({
        icon: "none",
        title: "不能为空",
        // duration: 5000
      })
      /*
      wx.showModal({
        title: "提醒",
        content: "不能为空"
      })*/
    }
  },
  getList() {
    const self = this
    wx.showLoading({
      mask: true
    })
    wx.request({
      method: "GET",
      url: "https://api.yizhanketang.cn/api/v1/todos",
      success(res) {
        self.setData({
          todoList: res.data.data
        })
        wx.hideLoading()
      }
    })
  },
  handleChange(event) {
    const { value } = event.detail
    this.setData({
      val: value
    })
  }
})
